package homeword;
import java.util.Scanner;
//输入一个金额转换为中文的金额
//格式：壹百万二万弎千百肆伍陆柒捌玖拾拾元
public class moneyConverse {
    public static void main(String[] args) {
      Scanner scanner=new Scanner(System.in);
      System.out.println("输入一个 0~9999999 金额我们将金额转换");
      int price=scanner.nextInt();
      //计算有多少位数，分配零
      int count=0;
      String result="";
      if(price<0||price>9999999){
          System.out.println("输入金额无效");
      }else
      {
          System.out.println("正在进行金额转换");
          //对金额取余后转换为中文金额
          while(price!=0){
              count++;
              int get=price%10;
               result = chinese(get)+result;
              price=price/10;
          }
      }
      //将零拼接
       count=7-count;//计算需要的零个数
        for (int i = 0; i < count; i++) {
            result="零"+result;
        }
        System.out.println(result);
        String []arr={"百万","拾万","万","千","百","拾","元"};
        //将单位连接起来
        for (int i = 0; i < arr.length; i++) {
            System.out.print(result.charAt(i));
            System.out.print(arr[i]);
        }
    }
    public static String chinese(int num){
        char[] c={'壹','二','弎','肆','伍','陆','柒','捌','玖','拾'};
        String result="";
        for (int i = 0; i < c.length; i++) {
            if(i+1==num){
                result=result+c[i];
            }
        }
        return result;
    }
}
